package com.yonyou.pmclouds.async.injvm;

import com.yonyou.pmclouds.async.AsyncTaskPusher;
import com.yonyou.pmclouds.basecom.async.AsyncInvocation;
import com.yonyou.pmclouds.basecom.async.AsyncInvocationInfo;
import com.yonyou.pmclouds.basecom.runtime.RuntimeEnvironment;
import org.springframework.beans.factory.annotation.Autowired;

public class InJvmAsyncTaskPusherImpl implements AsyncTaskPusher {
    @Autowired
    private AsyncInvocationQueueExecutor executor;

    @Override
    public AsyncInvocationInfo makeInfo() {
        // 设置状态信息
        AsyncInvocationInfo info = new AsyncInvocationInfo();
        info.setState(AsyncInvocation.InvocationState.STATE_PREPARING);
        info.setTenantId(RuntimeEnvironment.getTenantId());
        info.setUserId(RuntimeEnvironment.getLoginUserId());
        return info;
    }

    @Override
    public AsyncInvocationInfo prepare(AsyncInvocationInfo info) {
        return info;
    }

    @Override
    public AsyncInvocationInfo pushToExecutorQueue(AsyncInvocationInfo info) {
        executor.submit(info);
        return info;
    }
}
